// pages/orderdetails/orderdetails.js
var common = require('../../js/common.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_id:0,
    array: ['邮寄', '上门'],
    objectArray: [
      {
        id: 1,
        name: '邮寄'
      },
      {
        id: 2,
        name: '上门'
      },
    ],
    Jaddress:'',
    index: 0,
    money:0.00,
    remark:'',
    song:'',
    hui:'',
  },
  bindKeyInputAddress:function(e){
    this.setData({
      Jaddress: e.detail.value
    })
  },
  bindKeyInputSong: function (e) {
    this.setData({
      song: e.detail.value
    })
  },
  bindKeyInputHui: function (e) {
    this.setData({
      hui: e.detail.value
    })
  },
  okdan:function(){
      var weixiu_type = this.data.index;
      var money = this.data.money;
      var weixiu_remark = this.data.remark;
    var jib_address = this.data.Jaddress;
      var jisong_numbers = this.data.song;
      var jihui_numbers = this.data.hui;
    if (money==0){
      wx.showToast({
        title: '请输入金额',
        icon: 'none',
        duration: 1500
      })
      return;
    }
    if (weixiu_remark == '') {
      wx.showToast({
        title: '请输入备注',
        icon: 'none',
        duration: 1500
      })
      return;
    }
    if (weixiu_type == 1) {
      if (ji_address==''){
        wx.showToast({
          title: '请输入地址',
          icon: 'none',
          duration: 1500
        })
        return;
      }
    }
    var that = this;
    common.request(app.globalData.localUrl, 'shangjiajiedan', {
          weixiu_type: weixiu_type,
          money: money,
          weixiu_remark: weixiu_remark,
          ji_address: jib_address,
          jisong_numbers: jisong_numbers,
          jihui_numbers: jihui_numbers,
      order_id: that.data.order_id,
      shangjia_id: wx.getStorageSync('userInfo').id,
      },
      function (res) {
          if(res.data.code==1){
            wx.showToast({
              title: '接单成功',
              icon: 'success',
              mask: true
            })
          }else{
            wx.showToast({
              title: res.data.msg ,
              icon: 'none',
              duration: 1500
            })
          }
      }
    );
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var  that =this;

    this.setData({
      order_id: options.id
    })
    if (options.id){
      common.request(app.globalData.localUrl, 'orderDetail', {
        id: options.id
      },
        function (res) {
          console.log('订单详情', res)
          if (res.data.code == 1) {
            that.setData({
              address: res.data.data
            })
            // that.getdatalist();
          }
        }, 'rtype= post');
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  bindPickerChange:function(e){
    console.log(e);
    this.setData({
      index: e.detail.value
    })
  },
  bindKeyInput:function(e){
    this.setData({
      money: e.detail.value
    })
  },
  bindKeyInputRemark: function (e) {
    this.setData({
      remark: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})